<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form th:action="@{/addMedical}" method="post">
  <table border="1">
    <tr>
      <td colspan="2"><h2>添加核酸检测信息</h2></td>
    </tr>
    <tr>
      <td>被检测人姓名(*)</td>
      <td><input type="text" name="assayUser" required="required"></td>
    </tr>
    <tr>
      <td>被检测人手机号(*)</td>
      <td><input type="text" name="phone" required="required"></td>
    </tr>
    <tr>
      <td>被检测人身份证号(*)</td>
      <td><input type="text" name="cardNum" required="required"></td>
    </tr>
    <tr>
      <td>检测机构(*)</td>
      <td>
        <select name="hospitalId">
          <option value="">--请选择--</option>
          <option th:each="b: ${hostList}" th:value="${b.id}" th:text="${b.name}"></option>
        </select>
      </td>
    </tr>
    <tr>
      <td>检测日期(*)</td>
      <td><input type="text" id="time" name="assayTime" required="required"></td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="submit" value="添加">&nbsp;&nbsp;&nbsp;&nbsp;
        <button><a href="javascript:history.back(-1)">返回</a></button>
      </td>
    </tr>
  </table>
</form>
</body>
<script src="static/jQuery.js"></script>
<script>
  $("form").submit(function (){
      let data = /^\d{4}-\d{2}-\d{2}$/
      if(data.test($("#time").val())==false){
        alert("日期格式不正确!")
        return false;
      }
  })
</script>
</html>